package com.ys.timer;

import com.ys.entity.storage.TccFbaPlan;
import com.ys.service.storage.FbaInboundApiService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;

/**
 * @Author: fxz
 * @CreateTime: 2025-03-27
 * @Description: 亚马逊api定时器
 * @Version: 1.0
 */
public class TimerFbaInboundApiDaily {
    private static Logger logger = LoggerFactory.getLogger(TimerFbaInboundApiDaily.class);

    @Autowired
    private FbaInboundApiService fbaInboundApiService;


    /**
     * 每天下午5点
     * @throws Exception
     */
    @Scheduled(cron = "0 0 17 * * ?")
    public void updateShipmentTrackingDetails() throws Exception{
        logger.info("------------每天17点开始上传亚马逊追踪编码开始-----------------");
        List<TccFbaPlan> tccFbaPlanList = new TccFbaPlan()
                .where("(SELECT count(1) FROM TCC_FbaDeliverItem tfd WHERE tfd.ApiTrackStatus != 2 AND tfd.ApiTrackStatus != 3 AND tfd.FbaPlanBid = A.Bid) >0")
                .where("(SELECT count(1) FROM TCC_FbaDeliverSon tfs WHERE tfs.Transferno IS NOT NULL AND tfs.FbaPlanBid = A.Bid) >0")
                .queryList();
        for (TccFbaPlan tccFbaPlan : tccFbaPlanList){
            fbaInboundApiService.updateShipmentTrackingDetails(tccFbaPlan);
        }
        logger.info("------------每天17点开始上传亚马逊追踪编码结束-----------------");

    }
}
